package tech.yqyl.solo;

import com.google.common.base.Splitter;
import lombok.Data;
import tech.yqyl.StringUtil;

import javax.validation.constraints.NotNull;

@Data
public class Article {
    @NotNull
    private String oId;
    @NotNull
    private String articleTitle;
    @NotNull
    private String articleTags;
    @NotNull
    private String articleContent;

    /**** 以下字段在手动构造Article对象时可以为空 ****/
    private String articleAbstract;
    private String articleAbstractText;
    private String articleAuthorId;
    private String articlePermalink;
    private String articlePutTop;
    private Long articleCreated;
    private Long articleUpdated;
    private String articleRandomDouble;
    private String articleSignId;
    private String articleViewPwd;
    private String articleImg1URL;
    private int articleStatus;

    public String getFirstTag() {
        if( !StringUtil.isEmpty(articleTags) && articleTags.contains(",") ) {
            return Splitter.on(",").trimResults().omitEmptyStrings().splitToList(articleTags).get(0);
        }
        return articleTags;
    }
}
